<?php
require_once($_SERVER['DOCUMENT_ROOT']."/jeng/jeng.php");

class LoginProc extends JEngService
{
  function renderXml()
  {
	$doc=$this->emptyXML("login_result");
	$res=0;
	$user=$this->utils()->commonHelper()->gpVar("user");
	$password=$this->utils()->commonHelper()->gpVar("password");
	$rxml=JEngXRemote::s_render($this->conf()->get("service_server")."/login_user.php",
		array("user"=>$user,"password"=>$password),JEngXRemote::METH_POST);//,new JEngLogger("C:/dev/wamp/config/xrem.txt","DEBUG"));
	if ($rxml)
	{
	  if ($rxml->documentElement->nodeName=="login_user_result")
	  {
		$xr=$rxml->documentElement->attributes->getNamedItem('result')->nodeValue;
		if ($xr==0)
		{
			$uidnode=$rxml->getElementsByTagName('id');
			if ($uidnode)
			 if ($uidnode->item(0))
			 {
				$uid=$uidnode->item(0)->nodeValue;
				$sess=$this->utils()->commonHelper()->guid();
				$this->common_db()->queryf("UPDATE users SET active_code='%s' WHERE id=%d;",$sess,$uid);
				$this->utils()->xmlHelper()->appendAttribute($doc->documentElement,"usess",$sess);
				$res=1;
			}
		}
	  }
	}
	$this->utils()->xmlHelper()->appendAttribute($doc->documentElement,"result",$res);
	return $doc;
  }
}

$obj=new LoginProc();
echo $obj->render();

?>